﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SportManager.TrainingWizard
{
    public partial class AddTrainingWizard : Form
    {
        public Training training;

        public SlideA m_slideA;
        public SlideB m_slideB;
        public SlideC m_slideC;
        public SlideD m_slideD;

        public bool IsPlanningTraining = false;
        
        public AddTrainingWizard(DateTime startDate, Guid guid)
        {
            InitializeComponent();

            dialogHeader1.SetHeaderText("Создание тренеровки");
            dialogHeader1.SetDescriptionText("Задайте необходимые парамтры для создания тренеровки.");
            dialogHeader1.SetIcon(Resource.clicknrun_icon32);

            training = new Training(startDate.Year, startDate.Month, startDate.Day, guid);
            this.m_slideA = new SlideA(ref training, IsPlanningTraining);
            this.m_slideB = new SlideB(ref training);
            this.m_slideC = new SlideC(ref training, IsPlanningTraining);
            this.m_slideD = new SlideD(ref training);

            this.slideControl1.AddSlide(this.m_slideA);
            this.slideControl1.AddSlide(this.m_slideB);
            this.slideControl1.AddSlide(this.m_slideC);
            this.slideControl1.AddSlide(this.m_slideD);
            this.slideControl1.Selected = this.m_slideA;
            this.slideControl1.SlideSpeed = 400;
            this.slideControl1.SlideChanged += new EventHandler<SlickInterface.SlideChangedArgs>(this.slideControl1_SlideChanged);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.slideControl1.Backward();
        }

        private void slideControl1_SlideChanged(object sender, SlickInterface.SlideChangedArgs e)
        {
            this.button1.Enabled = this.slideControl1.HasPrevious;
            if (slideControl1.Selected == m_slideB)
            {
                IsPlanningTraining = m_slideA.IsPlanningTraining;
                if (training.Exercises.Count == 0)
                {
                    button2.Enabled = false;
                }
            }
            else
            {
                button2.Enabled = true;
                if (slideControl1.Selected == m_slideC)
                {
                    m_slideC.IsPlanningTraining = IsPlanningTraining;
                    m_slideC.ShowApproachs();
                }
                if (slideControl1.Selected == m_slideD)
                {
                    button2.Text = "Готово";
                }
                else
                {
                    button2.Text = "Далее >";
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (slideControl1.Selected == m_slideD)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            if (slideControl1.Selected == m_slideC)
            {
                this.slideControl1.ForwardTo(m_slideD.Name);
            }
            if (slideControl1.Selected == m_slideB)
            {
                this.slideControl1.ForwardTo(m_slideC.Name);
            }
            if (slideControl1.Selected == m_slideA)
            {
                training.StartDate = new DateTime(m_slideA.dateTimePicker1.Value.Year
                                                    , m_slideA.dateTimePicker1.Value.Month
                                                    , m_slideA.dateTimePicker1.Value.Day
                                                    , Convert.ToInt32(m_slideA.numericUpDown1.Value)
                                                    , Convert.ToInt32(m_slideA.numericUpDown2.Value)
                                                    , 0);
                training.FinishDate = new DateTime(m_slideA.dateTimePicker1.Value.Year
                                                    , m_slideA.dateTimePicker1.Value.Month
                                                    , m_slideA.dateTimePicker1.Value.Day
                                                    , Convert.ToInt32(m_slideA.numericUpDown3.Value)
                                                    , Convert.ToInt32(m_slideA.numericUpDown4.Value)
                                                    , 0);
                if (training.StartDate > training.FinishDate)
                {
                    MessageBox.Show("Тренировка должна начинаться раньше чем заканчивается !");
                    training.StartDate = new DateTime(training.StartDate.Year
                                                        , training.StartDate.Month
                                                        , training.StartDate.Day
                                                        , 0
                                                        , 0
                                                        , 0);
                    m_slideA.numericUpDown1.Value = training.StartDate.Hour;
                    m_slideA.numericUpDown2.Value = training.StartDate.Minute;
                }
                else
                {
                    slideControl1.ForwardTo(m_slideB.Name);
                }
            }
        }
    }
}

